﻿using System;
using System.Collections.Generic;
using System.Web;
using ihongma.WebData;
using HtmlAgilityPack;
namespace ihongma.WebData
{
    public class javascript
    {
        //Model.ajax ajaxmodel = new Model.ajax();
        

        private string html;

        public string Html
        {
            get { return html; }
            set { html = value; }
        }
        public HtmlNode body
        {
            get;
            set;
        }
        public javascript(string html,string id)
        {
           
            this.id = id;
            this.Html = html;
            this.body = HtmlHlep.getidinfo(this.Html, this.id);
        }
        public string id
        {
            get;
            set;
        }
        public string gettag(string str)
        {
            bool w=true;
            int i = 4;
            string rethtml="";
            if (this.body != null)
            {
                while (w)
                {


                    string temp = this.body.OuterHtml.Replace("<li>", "").Replace("PADDING-TOP:1px\'>", "PADDING-TOP:1px\'><em>").Replace("<br>", "</em>");
                    string ret = HtmlHlep.showinfo("//div/a[" + i + "]", str, temp);
                    if (ret != "")
                    {
                        rethtml = rethtml + ret + ",";
                    }
                    else
                    {
                        w = false;
                    }
                    i = i + 1;
                }
            }
            return rethtml;
            //return model;
        }
        public string getinfo(string str, string xpath)
        {
            if (this.body != null)
            {
                string temp = this.body.OuterHtml.Replace("<li>", "").Replace("PADDING-TOP:1px\'>", "PADDING-TOP:1px\'><em>").Replace("<br>", "</em>");

                return HtmlHlep.showinfo(xpath, str, temp);
            }
            else
            {
                return "";
            }
            //return model;
        }
        //public string getinfo(string str, string xpath)
        //{
        //    string temp=this.body.OuterHtml.Replace("<li>","").Replace("PADDING-TOP:1px\'>","PADDING-TOP:1px\'><em>").Replace("<br>","</em>");
        //    return HtmlHlep.showinfo(xpath, str,temp);
        //    //return model;
        //}
        public string getid(string id)
        {
            string str = "";
            if (this.body != null)
            {

                HtmlNode ret = HtmlHlep.getidinfo(body.OuterHtml, id);
                if (ret != null)
                {
                    str = ret.OuterHtml;
                }
            }
             return str;
        }
        public string  gettex(string xpath)
        {
            string str ="";
            if (this.body != null)
            {
                HtmlNode ret = HtmlHlep.gethtmlinfo(xpath, this.body);
                if (ret != null)
                {
                    str = ret.InnerText;
                }
            }
            return str;
        }
    }
}